//
//  CZEmoticonCell.swift
//  01 表情键盘
//
//  Created by danli on 15/12/28.
//  Copyright © 2015年 danli. All rights reserved.
//

import UIKit

class CZEmoticonCell: UICollectionViewCell {
    
    
    // MARK:属性
    var emoticon:DLEmoticon?{
        didSet
        {
            if let imagePath = emoticon?.imagePath
            {
                contentBtn.setImage(UIImage(contentsOfFile: imagePath), forState: UIControlState.Normal)
            }
            else
            {
                contentBtn.setImage(nil, forState: UIControlState.Normal)
            }
            contentBtn.setTitle(emoticon?.emoji, forState: UIControlState.Normal)
            
            if emoticon!.removeEmoticon
            {
                contentBtn.setImage(UIImage(named: "compose_emotion_delete_highlighted"), forState: UIControlState.Normal)
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
  
        prepareUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func prepareUI()
    {
        contentView.addSubview(contentBtn)
        
//        contentBtn.translatesAutoresizingMaskIntoConstraints = false
//      contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[contentBtn]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["contentBtn":contentBtn]))
//      contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[contentBtn]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["contentBtn":contentBtn]))
        
        contentBtn.frame = CGRectInset(bounds, 3, 3)
    }

    
    lazy var contentBtn:UIButton = {
       let btn = UIButton()
        btn.titleLabel?.font = UIFont.systemFontOfSize(32)
//        btn.backgroundColor = UIColor.redColor()
        
        // 关闭按钮的响应， 以免按钮拦截了collectionView的选中事件
        btn.userInteractionEnabled = false

        return btn
    }()
}
